<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Login</title>
    <script type="text/javascript" src="/js/jquery-3.5.1.min.js"></script>
    <script>
        function login() {
            let username = $("#username").val();
            let password = $("#password").val();
            const requestData = {'username': username, 'password': password}
            $.ajax({
                url: "http://localhost:8080/valid?username=" + username + "&password=" + password,
                type: "POST",
                // data: JSON.stringify(requestData),
                success: function (data) {
                    let code = data.code
                    if (code === 0) {

                        $(location).attr('href', "/index");
                    } else {
                        alert(data.message)
                    }

                }
            });
        }
    </script>
</head>
<body>
<table border="1">
    <tr>
        <td align="center" colspan="2">登录</td>
    </tr>
    <tr>
        <td align="right">用户名</td>
        <td align="left"><input type="text" id="username" name="username" value="" placeholder="请输入用户名"/></td>
    </tr>
    <tr>
        <td align="right">密码</td>
        <td align="left"><input type="password" id="password" name="password" value="" placeholder="请输入密码"></td>
    </tr>
    <tr aria-colspan="2">
        <td align="center" colspan="2"><input type="button" id="login" onclick="login()" value="登录"/></td>
    </tr>
</table>
</body>
</html>
